package com.bxait.toymail.ware.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


import com.bxait.com.utils.PageUtils;
import com.bxait.com.utils.R;
import com.bxait.com.vo.ware.MergeVo;
import com.bxait.com.vo.ware.PurchaseDoneVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.bxait.toymail.ware.entity.PurchaseEntity;
import com.bxait.toymail.ware.service.PurchaseService;



/**
 * import org.apache.shiro.authz.annotation.RequiresPermissions;
 * 采购信息
 *
 * @author chen
 * @email 2277411582@qq.com
 * @date 2023-03-13 22:41:32
 */
@RestController
@RequestMapping("ware/purchase")
public class PurchaseController {
    @Autowired
    private PurchaseService purchaseService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = purchaseService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		PurchaseEntity purchase = purchaseService.getById(id);

        return R.ok().put("purchase", purchase);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody PurchaseEntity purchase){
		purchaseService.save(purchase);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody PurchaseEntity purchase){
		purchaseService.updateById(purchase);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		purchaseService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }


    /**
     * @param mergeVo
     * @==============History===============<br/>
     * @Description // TODO  合并采购项
     * @Date 2023/3/25 2023/3/25
     * @Author < a href="2277411582@qq.com">chen</ a>
     * @return [com.bxait.com.vo.ware.MergeVo]
     */
    @RequestMapping(value = "/merge",method= RequestMethod.POST)
    public R merge(@RequestBody MergeVo mergeVo){

        purchaseService.mergePurchase(mergeVo);

        return R.ok();
    }


    /**
     * @param params
     * @==============History===============<br/>
     * @Description // TODO  查询未领取的采购单
     * @Date 2023/3/25 2023/3/25 
     * @Author < a href="2277411582@qq.com">chen</ a>
     * @return [java.util.Map<java.lang.String,java.lang.Object>]
     */
    @RequestMapping(value = "/unReceive/list",method= RequestMethod.GET)
    public R unReceiveList(@RequestParam Map<String, Object> params){

        PageUtils page = purchaseService.queryPageUnrReceivePurchase(params);
        return R.ok().put("data",page);
    }
    
    
    /**
     * @param ids
     * @==============History===============<br/>
     * @Description // TODO  领取采购单
     * @Date 2023/3/25 2023/3/25 
     * @Author < a href="2277411582@qq.com">chen</ a>
     * @return [java.util.List<java.lang.Long>]
     */
    @RequestMapping(value = "/received",method= RequestMethod.GET)
    public R received(@RequestParam List<Long> ids){
       purchaseService.received(ids);
        return R.ok();
    }

    /**
     * @param doneVo
     * @==============History===============<br/>
     * @Description // TODO  完成采购
     * @Date 2023/3/25 2023/3/25 
     * @Author < a href="2277411582@qq.com">chen</ a>
     * @return [PurchaseDoneVo]
     */
    @PostMapping("/done")
    public R finish(@RequestBody PurchaseDoneVo doneVo){
        purchaseService.done(doneVo);
        return R.ok();
    }
}
